import crypto from "node:crypto"
import SuperJSON from "superjson"
// import redisDriver from "unstorage/drivers/redis"
import fsDriver from "unstorage/drivers/fs-lite";
import { createStorage } from "unstorage";
// 在 所有请求后执行 && 每次刷新页面时执行
export default defineNitroPlugin(async (_nitroApp) => {
  const dataStorage = useStorage("data")
  // const storageFs = createStorage({
  //   driver: fsDriver({ base: "./data/users/" }),
  // });
  const u10057 = await dataStorage.hasItem("users:10057")
  if (!u10057)
    dataStorage.setItem("users:10057", { user: "user10057" })
  // const u10057_2 = await dataStorage.hasItem("users:10057")

  const data = await dataStorage.getItem("wid")
  // TODO category md5Hash
  const md5Hash = crypto
    .createHash("md5")
    .update(SuperJSON.stringify(data))
    .digest("hex")
    .slice(0, 8)

  // console.log("md5", md5Hash)
  // if (typeof data === "string") {
  // console.log("data string", data);
  // } else {
  // console.log("data other", SuperJSON.stringify(data))
  console.log("u10057", u10057);

  // }
})
